package com.zimmor.workqueue;

import com.rabbitmq.client.*;
import com.zimmor.util.RabbitmqUtil;

import java.io.IOException;

/**
 * @Author:zimmor
 * @Date: 2021/12/28 18:57
 * @Description 任务队列消费者
 * @version: 1.0.0
 */

public class customer2 {
    public static void main(String[] args) {
        //获取连接
        Connection connection = RabbitmqUtil.getConnection();
        //获取通道
        String queueName = "workqueue";
        //绑定队列
        try {
            Channel channel = connection.createChannel();
            channel.queueDeclare(queueName, false, false, false, null);
            //消费消息
            channel.basicConsume(queueName, true, new DefaultConsumer(channel) {

                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    System.out.println("body = " + new String(body));
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
